package com.xy.absfactory.order;


import com.xy.absfactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/10 9:04
 * @description
 */
public class OrderPizza {

    private Pizza pizza = null;

    private AbsFactory absFactory;



    public OrderPizza (AbsFactory factory) {
        setFactory(factory);
    }

    private void setFactory(AbsFactory factory) {
        String orderType = "";
        this.absFactory = factory;
        do {
            orderType = getType();
            pizza = absFactory.createPizza(orderType);
            if (this.pizza != null) {
                // 输出制作
                this.pizza.prepare();
                this.pizza.bake();
                this.pizza.cut();
                this.pizza.bake();
            } else {
                System.out.println("取消订购");
                break;
            }
        }while (true);
    }

    // 写一个方法，可以获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
